var app = getApp();
let myCanvasWidth = null;
let myCanvasHeight = null;
let unit = "";
let canvasDpr = 1;
Page({
  /**
   * 页面的初始数据
   */
  data: {
    imgPath: app.globalData.imgPath,
    Data: {},
    stop: false, //判断活动是否结束
    show: false,
    loadingImg: true,
    ithumb: "",
    canvasWidth: "",
    canvasHeight: "",
    timer: null,
    info: {},
    postData: {},
    room_id: "",
    shareBol: false,
    loadingMessage: "海报生成中",
    // 推广二维码id
    code_id:'',
    countTime: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getiPnoneBottom();
    if (options.scene) {
      let scene = decodeURIComponent(options.scene);
      if (scene) {
        let info_arr = [];
        info_arr = scene.split(",");
        this.data.RId = info_arr[0];
        this.data.CAT = info_arr[1];
        this.data.STAT = info_arr[2];
        this.data.REC = info_arr[3];
        app._setMid(info_arr[4]);
      }
      // if (scene) {
      //   let info_arr = [];
      //   info_arr = scene.split(",");
      //   for (let i = 0; i < info_arr.length; i++) {
      //     let chil_arr = [];
      //     chil_arr = info_arr[i].split("=");
      //     if (chil_arr[0] == "RId") {
      //       this.data.RId = chil_arr[1];
      //     } else if (chil_arr[0] == "CAT") {
      //       this.data.CAT = chil_arr[1];
      //     } else if (chil_arr[0] == "STAT") {
      //       this.data.STAT = chil_arr[1];
      //     } else if (chil_arr[0] == "REC") {
      //       this.data.REC = chil_arr[1];
      //     } else if (chil_arr[0] == "mid") {
      //       app._setMid(chil_arr[1]);
      //     }
      //   }
      // }
    } else {
      if (options.mid) {
        app._setMid(options.mid);
      }
      let {CAT,STAT,REC,RId} = options;
      this.data.RId = RId;
      this.data.CAT = CAT||'';
      this.data.STAT = STAT||'';
      this.data.REC = REC||'';
    }
    wx.getSystemInfo({
      success: (res) => {
        canvasDpr = wx.getSystemInfoSync().pixelRatio;
        if (res.windowWidth * 2 < 750) {
          unit = res.windowWidth / 620;
        } else {
          unit = res.windowWidth / 750;
        }
        myCanvasWidth = 620 * canvasDpr * unit;
        myCanvasHeight = 883 * canvasDpr * unit;
        this.setData({
          canvasWidth: parseInt(myCanvasWidth),
          canvasHeight: parseInt(myCanvasHeight),
        });
      },
    });
    this.getData();
  },
  getiPnoneBottom() {
    let that = this;
    try {
      var value = wx.getStorageSync("iPhoneBottom");
      if (value) {
        that.setData({
          iPnoneBottomBol: true,
        });
        // Do something with return value
      }
    } catch (e) {
      // Do something when catch error
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareTimeline: function () {
    let value = wx.getStorageSync("yz_uid");
    let mid = "";
    if (value) {
      mid = value;
    }
    return {
      title:
        "欢迎进入" +
        this.data.info.nickname +
        "的" +
        this.data.info.title +
        "直播间！",
      query: `RId=${this.data.RId}&CAT=${this.data.CAT}&STAT=1&REC=${this.data.REC}&&mid=${mid}`
    };
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var value = wx.getStorageSync("yz_uid");
    var mid = "";
    if (value) {
      mid = value;
    }
    return {
      title:
        "欢迎进入" +
        this.data.info.nickname +
        "的" +
        this.data.info.title +
        "直播间！",
      path: `/mircoApp/share-room/foreshow/foreshow?RId=${this.data.RId}&CAT=${this.data.CAT}&STAT=1&REC=${this.data.REC}&&mid=${mid}`
    };
  },
  showCloseBtn() {
    this.setData({
      show: false,
    });
  },

  getAvaterInfo() {
    let statusText =
      this.data.info.status == 0
        ? "预告"
        : this.data.info.status == 1
          ? "直播中 "
          : "回放";
    const ctx = wx.createCanvasContext("myCanvas");
    // 画banner图
    ctx.fillStyle = "#FFFFFF";
    ctx.fillRect(0, 0, this.data.canvasWidth, this.data.canvasHeight);
    let headWH = 56 * canvasDpr * unit;
    // {
    //   let avatarurl_width = headWH; //绘制的头像宽度
    //   let avatarurl_heigth = headWH; //绘制的头像高度
    //   let avatarurl_x = 215 * canvasDpr * unit; //绘制的头像在画布上的位置
    //   let avatarurl_y = 23 * canvasDpr * unit; //绘制的头像在画布上的位置
    //   ctx.save();
    //   ctx.beginPath(); //开始绘制
    //   //先画个圆   前两个参数确定了圆心 （x,y） 坐标  第三个参数是圆的半径  四参数是绘图方向  默认是false，即顺时针
    //   ctx.arc(
    //     avatarurl_width / 2 + avatarurl_x,
    //     avatarurl_heigth / 2 + avatarurl_y,
    //     avatarurl_width / 2,
    //     0,
    //     Math.PI * 2,
    //     false
    //   );
    //   ctx.clip(); //画好了圆 剪切  原始画布中剪切任意形状和尺寸。一旦剪切了某个区域，则所有之后的绘图都会被限制在被剪切的区域内 这也是我们要save上下文的原因
    //   if (this.data.postData.shop_logo) {
    //     ctx.drawImage(
    //       this.data.postData.shop_logo,
    //       avatarurl_x,
    //       avatarurl_y,
    //       avatarurl_width,
    //       avatarurl_heigth
    //     ); // 推进去图片，必须是https图片
    //   }
    //   ctx.restore(); //恢复之前保存的绘图上下文 恢复之前保存的绘图上下午即状态 还可以继续绘制
    // }
    ctx.setFontSize(13 * canvasDpr);
    ctx.setFillStyle("#000");
    ctx.fillText(
      this.data.info.shop_name,
      296 * canvasDpr * unit,
      60 * canvasDpr * unit
    );
    this.drawImg(
      ctx,
      560 * canvasDpr * unit,
      440 * canvasDpr * unit,
      this.data.postData.cover,
      this.data.postData.imgData.width,
      this.data.postData.imgData.height,
      30 * canvasDpr * unit,
      98 * canvasDpr * unit
    );
    // ctx.drawImage(this.data.postData.cover, 30 * unit, 98 * unit, 560 * unit, 440 * unit);
    {
      let x = 437 * canvasDpr * unit,
        y = 117 * canvasDpr * unit,
        w = 127 * canvasDpr * unit,
        h = 42 * canvasDpr * unit,
        fillColor = "#ff7200",
        r = 10 * canvasDpr;
      // if (2 * r > w || 2 * r > h) {
      // 	return false;
      // }
      ctx.save();
      ctx.translate(x, y);
      //绘制圆角矩形的各个边
      this.drawRoundRectPath(ctx, w, h, r);
      ctx.fillStyle = fillColor;
      ctx.fill();
      ctx.restore();
      ctx.setFillStyle("#fff");
      ctx.setFontSize(14 * canvasDpr);
      if (statusText.length == 2) {
        ctx.fillText(
          statusText,
          474 * canvasDpr * unit,
          148 * canvasDpr * unit
        );
      } else {
        ctx.fillText(
          statusText,
          460 * canvasDpr * unit,
          148 * canvasDpr * unit
        );
      }
    }
    let headWH_2 = 42 * canvasDpr * unit;
    {
      let avatarurl_width = headWH_2; //绘制的头像宽度
      let avatarurl_heigth = headWH_2; //绘制的头像高度
      let avatarurl_x = 52 * canvasDpr * unit; //绘制的头像在画布上的位置
      let avatarurl_y = 117 * canvasDpr * unit; //绘制的头像在画布上的位置
      ctx.save();
      ctx.beginPath(); //开始绘制
      //先画个圆   前两个参数确定了圆心 （x,y） 坐标  第三个参数是圆的半径  四参数是绘图方向  默认是false，即顺时针
      ctx.arc(
        avatarurl_width / 2 + avatarurl_x,
        avatarurl_heigth / 2 + avatarurl_y,
        avatarurl_width / 2,
        0,
        Math.PI * 2,
        false
      );
      ctx.clip(); //画好了圆 剪切  原始画布中剪切任意形状和尺寸。一旦剪切了某个区域，则所有之后的绘图都会被限制在被剪切的区域内 这也是我们要save上下文的原因
      ctx.drawImage(
        this.data.postData.shop_logo,
        avatarurl_x,
        avatarurl_y,
        avatarurl_width,
        avatarurl_heigth
      ); // 推进去图片，必须是https图片
      ctx.restore(); //恢复之前保存的绘图上下文 恢复之前保存的绘图上下午即状态 还可以继续绘制
    }

    {
      let text = this.data.info.nickname; //这是要绘制的文本';
      let chr = text.split(""); //这个方法是将一个字符串分割成字符串数组
      let temp = "";
      let row = [];
      ctx.setFontSize(28 * canvasDpr * unit);
      ctx.setFillStyle("#fff");
      for (let a = 0; a < chr.length; a++) {
        if (ctx.measureText(temp).width < 160 * canvasDpr) {
          temp += chr[a];
        } else {
          a--; //这里添加了a-- 是为了防止字符丢失，效果图中有对比
          row.push(temp);
          temp = "";
        }
      }
      row.push(temp); //如果数组长度大于2 则截取前两个
      if (row.length > 2) {
        let rowCut = row.slice(0, 2);
        let rowPart = rowCut[1];
        let test = "";
        let empty = [];
        for (let a = 0; a < rowPart.length; a++) {
          if (ctx.measureText(test).width < 306 * canvasDpr * unit) {
            test += rowPart[a];
          } else {
            break;
          }
        }
        empty.push(test);
        let group = empty[0] + "...";
        //这里只显示两行，超出的用...表示
        rowCut.splice(1, 1, group);
        row = rowCut;
      }
      for (let b = 0; b < row.length; b++) {
        ctx.fillText(
          row[b],
          108 * canvasDpr * unit,
          146 * canvasDpr * unit + b * (28 * canvasDpr * unit)
        );
      }
      ctx.restore(); //恢复之前保存的绘图上下文 恢复之前保存的绘图上下午即状态 还可以继续绘制
    }

    // ctx.setFontSize(13)
    // ctx.setFillStyle("#fff")
    // ctx.fillText(this.data.postData.nickname, 108 * unit, 146 * unit)
    ctx.save();
    {
      let text = this.data.info.title; //这是要绘制的文本';
      let chr = text.split(""); //这个方法是将一个字符串分割成字符串数组
      let temp = "";
      let row = [];
      ctx.setFontSize(28 * canvasDpr * unit);
      ctx.setFillStyle("#333333");
      for (let a = 0; a < chr.length; a++) {
        if (ctx.measureText(temp).width < 160 * canvasDpr) {
          temp += chr[a];
        } else {
          a--; //这里添加了a-- 是为了防止字符丢失，效果图中有对比
          row.push(temp);
          temp = "";
        }
      }
      row.push(temp); //如果数组长度大于2 则截取前两个
      if (row.length > 2) {
        let rowCut = row.slice(0, 2);
        let rowPart = rowCut[1];
        let test = "";
        let empty = [];
        for (let a = 0; a < rowPart.length; a++) {
          if (ctx.measureText(test).width < 306 * canvasDpr * unit) {
            test += rowPart[a];
          } else {
            break;
          }
        }
        empty.push(test);
        let group = empty[0] + "...";
        //这里只显示两行，超出的用...表示
        rowCut.splice(1, 1, group);
        row = rowCut;
      }
      for (let b = 0; b < row.length; b++) {
        ctx.fillText(
          row[b],
          41 * canvasDpr * unit,
          620 * canvasDpr * unit + b * (28 * canvasDpr * unit)
        );
      }
      ctx.restore(); //恢复之前保存的绘图上下文 恢复之前保存的绘图上下午即状态 还可以继续绘制
      ctx.setFontSize(12 * canvasDpr);
      ctx.setFillStyle("#ff7200");
      ctx.fillText(
        "直播时间 " + this.data.info.start_at,
        36 * canvasDpr * unit,
        730 * canvasDpr * unit
      );
    }
    let headWH_3 = 48 * canvasDpr * unit;
    {
      let avatarurl_width = headWH_3; //绘制的头像宽度
      let avatarurl_heigth = headWH_3; //绘制的头像高度
      let avatarurl_x = 35 * canvasDpr * unit; //绘制的头像在画布上的位置
      let avatarurl_y = 763 * canvasDpr * unit; //绘制的头像在画布上的位置
      ctx.save();
      ctx.beginPath(); //开始绘制
      //先画个圆   前两个参数确定了圆心 （x,y） 坐标  第三个参数是圆的半径  四参数是绘图方向  默认是false，即顺时针
      ctx.arc(
        avatarurl_width / 2 + avatarurl_x,
        avatarurl_heigth / 2 + avatarurl_y,
        avatarurl_width / 2,
        0,
        Math.PI * 2,
        false
      );
      ctx.clip(); //画好了圆 剪切  原始画布中剪切任意形状和尺寸。一旦剪切了某个区域，则所有之后的绘图都会被限制在被剪切的区域内 这也是我们要save上下文的原因
      ctx.drawImage(
        this.data.postData.avatar,
        avatarurl_x,
        avatarurl_y,
        avatarurl_width,
        avatarurl_heigth
      ); // 推进去图片，必须是https图片
      ctx.restore(); //恢复之前保存的绘图上下文 恢复之前保存的绘图上下午即状态 还可以继续绘制
    }

    {
      let text = this.data.info.member.nickname + "的分享"; //这是要绘制的文本';
      let chr = text.split(""); //这个方法是将一个字符串分割成字符串数组
      let temp = "";
      let row = [];
      ctx.setFontSize(28 * canvasDpr * unit);
      ctx.setFillStyle("#666666");
      for (let a = 0; a < chr.length; a++) {
        if (ctx.measureText(temp).width < 160 * canvasDpr) {
          temp += chr[a];
        } else {
          a--; //这里添加了a-- 是为了防止字符丢失，效果图中有对比
          row.push(temp);
          temp = "";
        }
      }
      row.push(temp); //如果数组长度大于2 则截取前两个
      if (row.length > 2) {
        let rowCut = row.slice(0, 2);
        let rowPart = rowCut[1];
        let test = "";
        let empty = [];
        for (let a = 0; a < rowPart.length; a++) {
          if (ctx.measureText(test).width < 306 * canvasDpr * unit) {
            test += rowPart[a];
          } else {
            break;
          }
        }
        empty.push(test);
        let group = empty[0] + "...";
        //这里只显示两行，超出的用...表示
        rowCut.splice(1, 1, group);
        row = rowCut;
      }
      for (let b = 0; b < row.length; b++) {
        ctx.fillText(
          row[b],
          94 * canvasDpr * unit,
          796 * canvasDpr * unit + b * (28 * canvasDpr * unit)
        );
      }
      ctx.restore(); //恢复之前保存的绘图上下文 恢复之前保存的绘图上下午即状态 还可以继续绘制
    }

    // ctx.setFontSize(13)
    // ctx.setFillStyle("#666666")
    // ctx.fillText(this.data.postData.m_nickname + '的分享', 94 * unit, 796 * unit)
    ctx.save();
    ctx.drawImage(
      this.data.postData.qr_code,
      408 * canvasDpr * unit,
      581 * canvasDpr * unit,
      180 * canvasDpr * unit,
      180 * canvasDpr * unit
    );
    ctx.restore(); //恢复之前保存的绘图上下文 恢复之前保存的绘图上下午即状态 还可以继续绘制
    ctx.setFontSize(12 * canvasDpr);
    ctx.setFillStyle("#333");
    ctx.fillText(
      "长按保存图片",
      430 * canvasDpr * unit,
      800 * canvasDpr * unit
    );
    ctx.draw(false, this.toimage());
  },
  drawImg(ctx, cWidth, cHeight, imgPath, imgWidth, imgHeight, x, y) {
    console.log("cWidth", cWidth);
    console.log("cHeight", cHeight);
    console.log("imgWidth", imgWidth);
    console.log("imgHeight", imgHeight);
    let dWidth = cWidth / imgWidth; // canvas与图片的宽度比例
    let dHeight = cHeight / imgHeight; // canvas与图片的高度比例
    if (
      (imgWidth > cWidth && imgHeight > cHeight) ||
      (imgWidth < cWidth && imgHeight < cHeight)
    ) {
      if (dWidth > dHeight) {
        ctx.drawImage(
          imgPath,
          0,
          (imgHeight - cHeight / dWidth) / 2,
          imgWidth,
          cHeight / dWidth,
          x,
          y,
          cWidth,
          cHeight
        );
      } else {
        ctx.drawImage(
          imgPath,
          (imgWidth - cWidth / dHeight) / 2,
          0,
          cWidth / dHeight,
          imgHeight,
          x,
          y,
          cWidth,
          cHeight
        );
      }
    } else {
      if (imgWidth < cWidth) {
        ctx.drawImage(
          imgPath,
          0,
          (imgHeight - cHeight / dWidth) / 2,
          imgWidth,
          cHeight / dWidth,
          x,
          y,
          cWidth,
          cHeight
        );
      } else {
        ctx.drawImage(
          imgPath,
          (imgWidth - cWidth / dHeight) / 2,
          0,
          cWidth / dHeight,
          imgHeight,
          x,
          y,
          cWidth,
          cHeight
        );
      }
    }
  },
  drawRoundRectPath(cxt, width, height, radius) {
    cxt.beginPath(0);
    //从右下角顺时针绘制，弧度从0到1/2PI
    cxt.arc(width - radius, height - radius, radius, 0, Math.PI / 2);

    //矩形下边线
    cxt.lineTo(radius, height);

    //左下角圆弧，弧度从1/2PI到PI
    cxt.arc(radius, height - radius, radius, Math.PI / 2, Math.PI);

    //矩形左边线
    cxt.lineTo(0, radius);

    //左上角圆弧，弧度从PI到3/2PI
    cxt.arc(radius, radius, radius, Math.PI, (Math.PI * 3) / 2);

    //上边线
    cxt.lineTo(width - radius, 0);

    //右上角圆弧
    cxt.arc(width - radius, radius, radius, (Math.PI * 3) / 2, Math.PI * 2);

    //右边线
    cxt.lineTo(width, height - radius);
    cxt.closePath();
  },
  toimage() {
    wx.hideLoading();
    this.setData({
      showBtn: true,
    });
    let that = this;
    setTimeout(() => {
      wx.canvasToTempFilePath({
        x: 0,
        y: 0,
        width: this.data.canvasWidth,
        height: this.data.canvasHeight,
        destWidth: this.data.canvasWidth * 4,
        destHeight: this.data.canvasHeight * 4,
        canvasId: "myCanvas",
        success: function (res) {
          console.log(res);
          var tempFilePath = res.tempFilePath;
          that.setData({
            ithumb: tempFilePath,
            loadingImg: false,
            show: true
          });
        },
        fail: function (res) {
          console.log(res);
        },
      });
    }, 1500);
  },
  saveShareImg: function () {
    wx.showLoading({
      title: "保存中",
    });
    wx.canvasToTempFilePath({
      x: 0,
      y: 0,
      width: this.data.canvasWidth,
      height: this.data.canvasHeight,
      destWidth: this.data.canvasWidth * 4,
      destHeight: this.data.canvasHeight * 4,
      canvasId: "myCanvas",
      success: function (res) {
        console.log(res);
        wx.saveImageToPhotosAlbum({
          filePath: res.tempFilePath,
          success(result) {
            wx.showToast({
              title: "图片保存成功",
              icon: "success",
              duration: 2000,
            });
          },
          fail: (res) => {
            wx.hideLoading();
          },
        });
      },
    });
  },
  getPoster() {
    if(this.data.ithumb){
      this.setData({
        show: true,
      });
      return;
    }
    wx.showLoading({
      title: '正在为您生成海报中，请稍后',
    })
    let urlStr = app.getNetAddresss("plugin.share-room.frontend.controllers.index.room-post");
    app._postNetWork({
      url: urlStr,
      showToastIn: false,
      data: {
        room_id: this.data.RId,
      },
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          this.setData({
            ['postData.qr_code']: res.data.qr_code,
          });
          this.downImg();
          wx.hideLoading()
        } else {
          wx.hideLoading()
          wx.showToast({
            icon: "none",
            title: res.msg,
            duration: 1500,
          });
        }
      },
      fail: function (res) {
        console.log(res.msg);
      },
    });
  },
  //预先下载图片数据
  downImg() {
    let that = this;
    wx.downloadFile({
      url: that.data.info.member.avatar, // 服务器返回的图片地址
      success: (res) => {
        that.setData({
          "postData.avatar": res.tempFilePath,
        });
        if (that.data.postData.qr_code) {
          wx.downloadFile({
            url: that.data.postData.qr_code, // 服务器返回的图片地址
            success: (res) => {
              that.setData({
                "postData.qr_code": res.tempFilePath,
              });
              wx.downloadFile({
                url: that.data.info.shop_logo, // 服务器返回的图片地址
                success: (res) => {
                  that.setData({
                    "postData.shop_logo": res.tempFilePath,
                  });
                  wx.downloadFile({
                    url: that.data.info.cover, // 服务器返回的图片地址
                    success: (res) => {
                      that.setData({
                        "postData.cover": res.tempFilePath,
                      });
                      // 获取图片信息
                      wx.getImageInfo({
                        src: that.data.postData.cover,
                        success(res) {
                          that.setData({
                            "postData.imgData": res,
                          });
                          that.getAvaterInfo();
                          console.log(res, "postData 失败");
                        },
                        fail: function (res) {
                          // 失败回调
                          that.setData({
                            loadingMessage:
                              "海报生成失败，用户头像图片下载失败",
                          });
                          console.log(res, "失败");
                        },
                      });
                    },
                    fail: function (res) {
                      // 失败回调
                      that.setData({
                        loadingMessage: "海报生成失败，直播封面图片下载失败",
                      });
                      console.log(res, "失败");
                    },
                  });
                },
                fail: function (res) {
                  // 失败回调
                  that.setData({
                    loadingMessage: "海报生成失败，直播封面图片下载失败",
                  });
                  console.log(res, "失败");
                },
              });
            },
            fail: function (res) {
              // 失败回调
              that.setData({
                loadingMessage: "海报生成失败，直播封面图片下载失败",
              });
              console.log(res, "失败");
            },
          });
        }
        // res.tempFilePath是网络图片的本地地址
      },
      fail: function (res) {
        that.setData({
          loadingMessage: "海报生成失败，主播头像图片下载失败",
        });
        // 失败回调
        console.log(res, "失败");
      },
    });
  },
  getData() {
    let urlStr = app.getNetAddresss(
      "plugin.share-room.frontend.controllers.index.room-notice"
    );
    app._postNetWork({
      url: urlStr,
      showToastIn: false,
      data: {
        room_id: this.data.RId,
      },
      success: (resdata)=> {
        var res = resdata.data;
        if (res.result == 1) {
          if (res.data.status == 1) {
            return wx.showModal({
              title: "提示",
              content: "已开播，正在为您跳至直播间！",
              showCancel: false,
              success:(res)=> {
                if (res.confirm) {
                  wx.redirectTo({
                    url: `/mircoApp/share-room/player/player?RId=${this.data.RId}&CAT=${this.data.CAT}&STAT=1&REC=${this.data.REC}`
                  });
                }
              },
            });
          }
          if (res.data.status == 2) {
            return wx.showModal({
              title: "提示",
              content: "直播已结束，正在为您跳至主播页面！",
              showCancel: false,
              success:(res)=> {
                if (res.confirm) {
                  wx.redirectTo({
                    url: `/mircoApp/share-room/player/player?RId=${this.data.RId}&CAT=${this.data.CAT}&STAT=2&REC=${this.data.REC}`
                  });
                }
              },
            });
          }
          this.setData({
            info: res.data,
          });


        } else {
          wx.showToast({
            icon: "none",
            title: res.msg,
            duration: 1500,
          });
        }
      },
      fail: function (res) {
        console.log(res.msg);
      },
    });
  },
  finishtime(){
    this.setData({
      ['info.status']: 1
    })
    this.pollStautsTimer = setInterval(() => {
      this.pollingLiveStatus();//轮询直播状态，开播直接跳转
    }, 15000);
  },
  async pollingLiveStatus() {
    app._postNetWork({
      url: app.getNetAddresss("plugin.share-room.frontend.controllers.index.room-notice"),
      data: {
        room_id: this.data.RId,
      },
      success: (resdata)=> {
        var res = resdata.data;
        if (res.result == 1 && res.data.status == 1){
          wx.showToast({
            icon: "none",
            title: '已开播，正在为您跳至直播间！',
            duration: 1500,
          });
          wx.redirectTo({
            url: `/mircoApp/share-room/player/player?RId=${this.data.RId}&CAT=${this.data.CAT}&STAT=1&REC=${this.data.REC}`
          });
        } 
      },
      fail: function (res) {
        console.log(res.msg);
      },
    });
  },
});
